import { httpClient } from '@/utils/http/axios';
import { ErrorMessageMode } from '#/axios';
import { AjaxResult } from '@/api/model';
import { PageRequest, PageData } from '@/utils/common/types';
import { DictInputDto, DictOutputDto } from './dict.data';

enum DictApi {
  ReadDict = '/api/admin/dict/readdict',
  CreateDict = '/api/admin/dict/createdict',
  UpdateDict = '/api/admin/dict/updatedict',
  DeleteDict = '/api/admin/dict/deletedict',
}

export function ReadDict(request: PageRequest, mode: ErrorMessageMode = 'message') {
  return httpClient.post<PageData<DictOutputDto>>(
    {
      url: DictApi.ReadDict,
      params: request,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function CreateDict(dtos: DictInputDto[], mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: DictApi.CreateDict,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function UpdateDict(dtos: DictInputDto[], mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: DictApi.UpdateDict,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function DeleteDict(ids: string[], mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: DictApi.DeleteDict,
      params: ids,
    },
    {
      errorMessageMode: mode,
    },
  );
}
